package cn.star.jots.carousel.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.carousel.pojo.dto.CarouselQuery;
import cn.star.jots.carousel.pojo.dto.CarouselSaveParam;
import cn.star.jots.carousel.pojo.vo.CarouselVO;
import cn.star.jots.carousel.service.CarouselService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/carousel")
@Api(tags = "轮播图管理")
@Slf4j
public class CarouselController {

    @Autowired
    CarouselService carouselService;

    @GetMapping("/select")
    @ApiOperation(value = "查询轮播图")
    public JsonResult select(CarouselQuery carouselQuery) {
        log.info("查询轮播图:carouselQuery={}", carouselQuery);
        List<CarouselVO> list = carouselService.selectAll(carouselQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存轮播图")
    public JsonResult save(CarouselSaveParam carouselSaveParam){
        log.info("保存轮播图:carouselSaveParam={}", carouselSaveParam);
        carouselService.save(carouselSaveParam);
        return JsonResult.ok();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除轮播图")
    public JsonResult delete(@PathVariable Long id){
        log.info("删除轮播图:id={}", id);
        carouselService.delete(id);
        return JsonResult.ok();
    }

}
